﻿/*************************************************************************************
 * 文 件 名:   HK_ShortAnswerItem
 * 
 * 描    述:   简答题模板类
 * 
 * 版    本：  V1.0
 * 创 建 者：  京产肠饭
 * 创建时间：  2021/11/25
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using UnityEngine.UI;

namespace HKTools
{
    public class HK_ShortAnswerItem : HK_QuesItem
    {
        public InputField inputField;

        string answer;

        public void InitQuesItem(HK_ShortAnswerData quesData, int id)
        {
            ID_Txt.text = id.ToString() + "、";

            answer = quesData.Answer;

            quesName_Txt.text = quesData.QuesName;

            inputField.onEndEdit.AddListener(input =>
            {
                if (input == answer)
                    isCorrect = true;
                else
                    isCorrect = false;
            });

            analysis_Txt.text = quesData.Analysis;
        }

        public void DisableInput()
        {
            inputField.interactable = false;
        }

        public override bool IsDone()
        {
            isDone = true;

            if (string.IsNullOrEmpty(inputField.text.Trim()))
                isDone = false;

            return isDone;
        }

        public override bool IsCorrect()
        {
            return isCorrect;
        }
    }
}